<?php
if (!defined("_ECRIRE_INC_VERSION")) return;
global $tables_principales;

function ecatalogue_declarer_tables_interfaces($interface){
    $interface['table_des_tables']['ecatalogue_products'] = 'ecatalogue_products';
    $interface['table_des_tables']['ecatalogue_options'] = 'ecatalogue_options';
    $interface['table_des_tables']['ecatalogue_articles_options'] = 'ecatalogue_articles_options';
    $interface['table_des_tables']['ecatalogue_rubriques_groupes'] = 'ecatalogue_rubriques_groupes';
    $interface['table_des_tables']['ecatalogue_proprietes'] = 'ecatalogue_proprietes';
    $interface['table_des_tables']['ecatalogue_groupes'] = 'ecatalogue_groupes';
    $interface['table_des_tables']['ecatalogue_currencies'] = 'ecatalogue_currencies';
    $interface['table_des_tables']['ecatalogue_rubriques_currencies'] = 'ecatalogue_rubriques_currencies';
    $interface['table_des_tables']['ecatalogue_articles_similars'] = 'ecatalogue_articles_similars';
    $interface['table_des_tables']['ecatalogue_articles_accessoires'] = 'ecatalogue_articles_accessoires';
    $interface['table_des_tables']['ecatalogue_composites_articles'] = 'ecatalogue_composites_articles';

    //Doesn't work
    $interface['tables_jointures']['spip_ecatalogue_options']['id_article']= 'ecatalogue_articles_options';

    return $interface;
}

function ecatalogue_declarer_tables_principales($tables_principales){
    // spip_ecatalogue_products
    $ecatalogue_products = array(
        "id_article" 	=> "bigint(21) NOT NULL AUTO_INCREMENT",
        "price" 		=> "float NOT NULL",
        "priceold" 		=> "float NOT NULL",
        "sku" 	        => "varchar(50) NOT NULL",
        "quantity"      => "int(11) NOT NULL",
        "weight" 	    => "float NOT NULL",
        "width" 	    => "float NOT NULL",
        "height"    	=> "float NOT NULL",
        "length" 	    => "float NOT NULL",
        "id_equipment" 	=> "bigint(21) NOT NULL", // ID комплектации
        "is_composite" 	=> "tinyint(1) NOT NULL DEFAULT 0", // Признак того, является ли товар составным, то есть состоит из нескольких других товаров
        "is_separate" => "tinyint(1) NOT NULL DEFAULT 1", // Признак того, что товар является отдельной единицей (например в корзине). Это значение нужно выставить 0, например для товаров, которые входят в составной товар, и не должны выводится как отдельные
        "sold_in_packages" => "tinyint(1) NOT NULL DEFAULT 0", // Признак того, что товар продается упаковками
        "num_in_package"=> "int(11) NOT NULL DEFAULT 1", // Количество в упаковке
        "extra1" 	    => "varchar(255) NOT NULL",
        "extra2" 	    => "varchar(255) NOT NULL",
        "extra3" 	    => "varchar(255) NOT NULL",
        "extra4"        => "varchar(255) NOT NULL",
        "maj"           => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
    );
    $ecatalogue_products_key = array(
        "PRIMARY KEY"	=> "id_article"
    );
    $tables_principales['spip_ecatalogue_products'] =
        array('field' => &$ecatalogue_products, 'key' => &$ecatalogue_products_key);

    // spip_ecatalogue_options
    $ecatalogue_options = array(
        "id_option" 	   => "bigint(21) NOT NULL AUTO_INCREMENT",
        "titre" 		   => "varchar(255) NOT NULL",
        "id_propriete"        => "bigint(21) NOT NULL",
        "id_mot"           => "bigint(21) NOT NULL",
        "maj"              => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
    );
    $ecatalogue_options_key = array(
        "PRIMARY KEY"	=> "id_option"
    );
    $tables_principales['spip_ecatalogue_options'] =
        array('field' => &$ecatalogue_options, 'key' => &$ecatalogue_options_key);

    // spip_ecatalogue_proprietes
    $ecatalogue_proprietes = array(
        "id_propriete" => "bigint(21) NOT NULL AUTO_INCREMENT",
        "id_groupe"     => "bigint(21) NOT NULL",
        "titre"     => "varchar(255) NOT NULL",
        "type"     => "enum('checkbox','select','radio') DEFAULT 'checkbox'",
        "soustitre"     => "varchar(255) NOT NULL",
        "texte"     => "text NOT NULL",
        "maj"       => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
    );
    $ecatalogue_proprietes_key = array(
        "PRIMARY KEY"	=> "id_propriete"
    );
    $tables_principales['spip_ecatalogue_proprietes'] =
        array('field' => &$ecatalogue_proprietes, 'key' => &$ecatalogue_proprietes_key);


    // spip_ecatalogue_groupes
    $ecatalogue_groupes = array(
        "id_groupe" 	   => "bigint(21) NOT NULL AUTO_INCREMENT",
        "titre" 		   => "varchar(255) NOT NULL",
        "soustitre"        => "varchar(255) NOT NULL",
        "texte" 		   => "text NOT NULL",
        "maj"              => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
    );
    $ecatalogue_groupes_key = array(
        "PRIMARY KEY"	=> "id_groupe"
    );
    $tables_principales['spip_ecatalogue_groupes'] =
        array('field' => &$ecatalogue_groupes, 'key' => &$ecatalogue_groupes_key);

    // spip_ecatalogue_currencies
    $ecatalogue_currencies = array(
        "id_currency" => "bigint(21) NOT NULL AUTO_INCREMENT",
        "titre"     => "varchar(255) NOT NULL",
        "sign_pre"     => "varchar(50) NOT NULL",
        "sign_after"     => "varchar(50) NOT NULL",
        "code"     => "varchar(5) NOT NULL",
        "rate"     => "float NOT NULL",
        "maj"       => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
    );
    $ecatalogue_currencies_key = array(
        "PRIMARY KEY"	=> "id_currency",
        "INDEX" => "code"
    );
    $tables_principales['spip_ecatalogue_currencies'] =
        array('field' => &$ecatalogue_currencies, 'key' => &$ecatalogue_currencies_key);

    // spip_ecatalogue_articles_similars
    $ecatalogue_articles_similars = array(
        "id_article" => "bigint(21) NOT NULL", // Main article ID
        "id_similar" => "bigint(21) NOT NULL", // Similar article ID
        "maj"       => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
    );
    $ecatalogue_articles_similars_key = array(
        "INDEX"	=> "id_article",
        "INDEX" => "id_similar"
    );
    $tables_principales['spip_ecatalogue_articles_similars'] =
        array('field' => &$ecatalogue_articles_similars, 'key' => &$ecatalogue_articles_similars_key);

    // spip_ecatalogue_articles_accessoires
    $ecatalogue_articles_accessoires = array(
        "id_article" => "bigint(21) NOT NULL", // Main article ID
        "id_accessoire" => "bigint(21) NOT NULL", // Similar article ID
        "maj"       => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
    );
    $ecatalogue_articles_accessoires_key = array(
        "INDEX"	=> "id_article",
        "INDEX" => "id_accessoire"
    );
    $tables_principales['spip_ecatalogue_articles_accessoires'] =
        array('field' => &$ecatalogue_articles_accessoires, 'key' => &$ecatalogue_articles_accessoires_key);

    // spip_ecatalogue_composites_articles
    $ecatalogue_composites_articles = array(
        "id_composite" => "bigint(21) NOT NULL", // Composite article ID
        "id_article" => "bigint(21) NOT NULL", // Compoment article ID
        "quantity" => "int(11) NOT NULL DEFAULT 1", // Quantity of product in composite product
        "maj"       => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
    );
    $ecatalogue_composites_articles_key = array(
        "INDEX"	=> "id_composite",
        "INDEX" => "id_article"
    );
    $tables_principales['spip_ecatalogue_composites_articles'] =
        array('field' => &$ecatalogue_composites_articles, 'key' => &$ecatalogue_composites_articles_key);

    return $tables_principales;
}

function ecatalogue_declarer_tables_auxiliaires($auxiliary_tables){

    // spip_ecatalogue_articles_options
    $ecatalogue_articles_options = array(
        "id_article" 	   => "bigint(21) NOT NULL",
        "id_option" 	   => "bigint(21) NOT NULL",
        "maj"              => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
    );
    $ecatalogue_articles_options_key = array(
        "PRIMARY KEY"	=> "id_article, id_option"
    );
    $auxiliary_tables['spip_ecatalogue_articles_options'] =
        array('field' => &$ecatalogue_articles_options, 'key' => &$ecatalogue_articles_options_key);

    // spip_ecatalogue_rubriques_groupes
    $ecatalogue_rubriques_groupes = array(
        "id_rubrique" 	   => "bigint(21) NOT NULL",
        "id_groupe" 	   => "bigint(21) NOT NULL",
        "maj"              => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
    );
    $ecatalogue_rubriques_groupes_key = array(
        "PRIMARY KEY"	=> "id_rubrique, id_groupe"
    );
    $auxiliary_tables['spip_ecatalogue_rubriques_groupes'] =
        array('field' => &$ecatalogue_rubriques_groupes, 'key' => &$ecatalogue_rubriques_groupes_key);

    // spip_ecatalogue_rubriques_currencies
    $ecatalogue_rubriques_currencies = array(
        "id_rubrique" 	   => "bigint(21) NOT NULL",
        "id_currency" 	   => "bigint(21) NOT NULL",
        "maj"              => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
    );
    $ecatalogue_rubriques_currencies_key = array(
        "PRIMARY KEY"	=> "id_rubrique, id_currency"
    );
    $auxiliary_tables['spip_ecatalogue_rubriques_currencies'] =
        array('field' => &$ecatalogue_rubriques_currencies, 'key' => &$ecatalogue_rubriques_currencies_key);

    return $auxiliary_tables;
}

?>